package com.ita.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ita.service.IBookService;
import com.ita.service.impl.BookServiceImpl;
import com.ita.vo.Book;

@Controller
@RequestMapping("/book1")
public class CopyOfBookController {

	private IBookService service=new BookServiceImpl();
	
	@RequestMapping(value="/showAllBook",method=RequestMethod.GET)
	@ResponseBody
	public List<Book> showAll(){
		System.out.println("showAllBook");
		List<Book> list=service.queryAll();
		System.out.println(list);
		return list;
	}
	
	
	@RequestMapping(value="/{bookid}",method=RequestMethod.DELETE)
	@ResponseBody
	public String deleteBook(@PathVariable String bookid){
		service.deleteById(bookid);
		return "success";
	}
	
	@RequestMapping(value="/add",method=RequestMethod.POST)
//	@ResponseBody
	public String addBook(String bookname,String author,int price){
		Book book=new Book(bookname, author, price);
		service.insert(book);
		return "success";
	}
	
	@RequestMapping(value="/update",method=RequestMethod.POST)
//	@ResponseBody
	public String updateBook(String bookid,String bookname,String author,int price){
		Book book=new Book(bookid,bookname, author, price);
		service.update(book);
		return "success";
	}
}
